#ifndef CPU_H
#define CPU_H

#include <QObject>
#include <functional>
#include <unordered_map>

class Cpu
{
public:
    // Typedefs
    using TaskProcessFunctionType = std::function<void(QVariantMap)>;
public:
    Cpu();
    ~Cpu();
public:
    template <class T>
    void setOn(const QString &type, T *thisptr, void (T::* func)(QVariantMap));
    void setOn(const QString &type, TaskProcessFunctionType func);
public:
    void onMessage(const QString &type, const QVariantMap &args);
public:
    // public static methods:
    static Cpu *instance();
private:
    // internal static variables
    static Cpu *_instance;
private:
    std::unordered_map<std::string, TaskProcessFunctionType> tasks = std::unordered_map<std::string, TaskProcessFunctionType>(1024);
};

template <class T>
inline void Cpu::setOn(const QString &type, T *thisptr, void (T::* func)(QVariantMap))
{
    return setOn(type, std::bind(func, thisptr, std::placeholders::_1));
}


#endif // CPU_H
